package logging

import (
	"gitee.com/huerbiao/robot/pkg/logger"

	"github.com/gin-gonic/gin"
)

func RegisterLog() gin.HandlerFunc {
	//logger.Init()
	return gin.LoggerWithConfig(gin.LoggerConfig{
		Formatter: func(params gin.LogFormatterParams) string {
			//delete(params.Request.Header, "Aha-S-Tk")
			logFormat := map[string]interface{}{
				"response_time": params.TimeStamp.Format("2006/01/02 - 15:04:05"),
				"http_code":     params.StatusCode,
				"latency_time":  params.Latency.Milliseconds(),
				"client_ip":     params.ClientIP,
				"method":        params.Method,
				"path_url":      params.Request.URL.Path,
				"full_path":     params.Path,
				"error_message": params.ErrorMessage,
				"header":        params.Request.Header,
			}
			logger.Info(logFormat)
			return ""
		},
		Output: nil,
		SkipPaths: []string{
			"/ping",
			"/healthz",
		},
	})
}
